package com.boot.controller;


import com.boot.pojo.User;
import com.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/user/register")
    public String doRegister(User user){
        try {
            userService.register(user);
            return "redirect:/login";
        } catch (Exception e) {
            e.printStackTrace();
            return "redirect:/register";
        }

    }

    @RequestMapping("/register")
    public String toRegister(){
        return "register";
    }

    @RequestMapping("/user/save")
    @ResponseBody
    public String save(){
        return "save";
    }

    @RequestMapping("/user/delete")
    @ResponseBody
    public String delete(){
        return "delete";
    }

    @RequestMapping("/user/update")
    @ResponseBody
    public String update(){
        return "/user/update";
    }

    @RequestMapping("/user/select")
    @ResponseBody
    public String select(){
        return "/user/select";
    }
}
